package day1;

/**
 * @author pacai
 * @version 1.0
 */
@SuppressWarnings("all")
public class BubbleSort {


    public static void BubbleSort(int[] arr) {
        if(arr == null || arr.length < 2) {
            return;
        }
        int end = arr.length - 1;
        for (; end >= 0; end--) {
            for (int second = 1; second <= end; second++) {
                if (arr[second] < arr[second - 1]) {
                    swap(arr, second, second - 1);
                }
            }
        }
    }


    public static void swap(int[] arr, int i, int j) {
        if (i != j) {
            arr[i] ^= arr[j];
            arr[j] ^= arr[i];
            arr[i] ^= arr[j];
        }
    }
}


